﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace CrossesGrav.WorkClasses
{
   
    class ARGBFont
    {
        
        
        Dictionary<char, Bitmap> fontBase = new Dictionary<char, Bitmap>();
            public PictureBox this[String line, PictureBox p, bool make_event]
            {
                get
                {
                    int j = 0;
                    Bitmap t = new Bitmap(line.Length * 24, 40);
                    p.Image = t;
                    Graphics g = Graphics.FromImage(t);
                    p.BackColor = (Color.FromArgb(0, 0, 0, 255));
                    p.Cursor = Cursors.Hand;
                    if (make_event)
                        p.MouseClick += new MouseEventHandler(Game.Click_Item);
                    for (int i = 0; i < line.Length; i++)
                    {
                        g.DrawImage(fontBase[line[i]], new Rectangle(j, 0, 24, 40));
                        j += 24;
                    }
                        return p;
                }
            }

            public void Add(char symbol, Bitmap image)
            {
                fontBase.Add(symbol, image);
            }

            private Bitmap cropImage(Image img, Rectangle cropArea)
            {
                Bitmap bmpImage = new Bitmap(img);
                Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
                return bmpCrop;
            }

            public ARGBFont(Bitmap font, string font_text)
            {
                 int j = 0;
                 for (int i = 0; i < font_text.Length; i++)
            {
                Bitmap t = cropImage(font, new Rectangle(j, 0, 24, 40));
                this.Add(font_text[i], t);
                j+=Convert.ToInt32(24);
            }
                 GC.Collect();
            }
        }

    }

